<?php

namespace App\Http\Controllers;

use App\Models\Article;
use Illuminate\Http\Request;

class ArticleController extends Controller
{
    public function indexList(Request $request): \Illuminate\Http\JsonResponse
    {
        $articles = Article::query()
            ->select([
                'id',
                'title',
                'order',
            ])
            ->orderBy('order', 'desc')
            ->limit(5)
            ->get();

        return response()
            ->json([
                'status' => 0,
                'data' => $articles
            ]);
    }

    public function detail(Request $request): \Illuminate\Http\JsonResponse
    {
        $id = $request->get('id');
        $article = Article::find($id);

        return response()
            ->json([
                'status' => 0,
                'id' => $id,
                'data' => $article
            ]);
    }
}
